package org.snail.department.service.manager;

import lombok.extern.log4j.Log4j;
import org.snail.constant.GroupConstant;
import org.snail.department.service.push.DeptInfoPushService;
import org.snail.dept.bean.DepartDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 管理部门队列消息
 */
@Component
@Log4j
public class DeptInfoManager {

    @Autowired
    private DeptInfoPushService deptInfoPushService;

    /**
     * 从根目录更新部门
     */
    public void generateChildDeptByRoot() {
        DepartDO departDO = new DepartDO();
        departDO.setId(GroupConstant.ROOT_DEPT_ID);
        executeDeptQueue(departDO, GroupConstant.GROUP_TYPE);
    }

    /**
     * 获取子级部门信息
     * @param departDO
     */
    public void generateChildDept(DepartDO departDO) {
        log.debug("`````````````````````获取子级部门，显示当前部门信息:" + departDO);
        executeDeptQueue(departDO, GroupConstant.CHILD_GROUP_LIST_TYPE);
    }

    /**
     * 设置部门Manager信息
     * @param departDO
     */
    public void setDeptmentManager(DepartDO departDO) {
        log.debug("`````````````````````获取部门，设置部门Manager信息:" + departDO);
        executeDeptQueue(departDO, GroupConstant.DEPT_MANAGER_TYPE);
    }

    /**
     * 获取子级部门信息
     * @param departDO
     * @param typeID 同步规则 1、获取下级部门 2、获取当前部门员工
     */
    public void executeDeptQueue(DepartDO departDO, Integer typeID) {
        log.debug("`````````````````````获取子级部门，显示当前部门信息:" + departDO);
        if(null!=typeID) {
            departDO.setDeptStatus(typeID);
        }
        deptInfoPushService.push(departDO);
    }
}
